package org.ffmmx.gxhotel.controller;

import org.apache.commons.lang3.StringUtils;
import org.ffmmx.common.util.TokenUtil;
import org.ffmmx.gxhotel.common.WithLog;
import org.ffmmx.gxhotel.model.Ok;
import org.ffmmx.gxhotel.model.Result;
import org.ffmmx.gxhotel.model.specialuserout.Stationlist;
import org.ffmmx.gxhotel.repository.stationlist.StationlistRepo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

@RestController
@RequestMapping("/api")
public class StationlistCtrl implements WithLog {
    @Autowired
    private StationlistRepo stationlistRepo;
    @RequestMapping(path = "/stations",method = RequestMethod.GET)
    public Result<Stationlist> list(@RequestParam String token, @RequestParam String stationID) {
        Result<Stationlist> result = null;
        try {
            if (StringUtils.isEmpty(stationID)) {
                throw new RuntimeException("旅馆代码为空");
            }
            Stationlist station = stationlistRepo.findByStationid(stationID);
            result = new Ok<>(station);
        } catch (RuntimeException e) {
            result = new Result<>();
            result.setSuccess(false);
            result.setMsg("获取旅馆信息发生错误:"+e.getMessage());
            if (logger().isDebugEnabled()) {
                result.setException(e);
            }
            logger().error(result.getMsg(),e);
        }
        return result;
    }
}
